package com.beijing.demo.stack;

/**
 * 曹旭
 * 2025/5/7
 * 最小栈  https://leetcode.cn/problems/min-stack/
 */
public class MinStack {

    public int[] data;
    public int[] min;
    public int size;
    public int len = 8001;
    public MinStack() {
        data = new int[len];
        min = new int[len];
        size = 0;
    }

    public void push(int val) {
        data[size] = val;
        if(size == 0 || val < min[size - 1]){
            min[size] = val;
        }else {
            min[size] = min[size - 1];
        }
        size++;
    }

    public void pop() {
        size--;
    }

    public int top() {
        return data[size - 1];
    }

    public int getMin() {
        return min[size - 1];
    }

    public static void main(String[] args) {
        MinStack stack = new MinStack();
        stack.push(-2);
        stack.push(0);
        stack.push(-3);
        stack.getMin();
    }


}
